<template>
  <div>
    <van-nav-bar title="栏目管理" left-text="返回" left-arrow @click-left="onClickLeft" />
    <div class="mainWrapper">
      <h2>点击删除以下频道</h2>
      <div class="enable list">
        <div class="item" v-for="(item, index) in enableList" :key="item.id" @click="disableCategory(index)">{{ item.name }}</div>
      </div>
      <h2>点击添加以下频道</h2>
      <div class="disable list">
        <div class="item" v-for="(item, index) in disableList" :key="item.id" @click="enableCategory(index)">{{ item.name }}</div>
      </div>
    </div>
  </div>
</template>

<script>
import { Toast } from 'vant'
export default {
  data() {
    return {
      enableList: [],
      disableList: []
    }
  },
  created() {
    this.$axios({
      url: '/category'
    }).then(res => {
      this.enableList = res.data.data
    })
  },
  methods: {
    disableCategory(index) {
      if (this.enableList.length === 1) {
        return
      }

      this.disableList.push(this.enableList[index])
      this.enableList.splice(index, 1)
    },
    enableCategory(index) {
      this.enableList.push(this.disableList[index])
      this.disableList.splice(index, 1)
    },
    onClickLeft() {
      this.$router.back()
      Toast('返回')
    }
  }
}
</script>

<style lang="less" scoped>
.mainWrapper {
  padding: 20px;
}
h2 {
  font-size: 14px;
  font-weight: normal;
}
.list {
  display: flex;
  flex-wrap: wrap;
  .item {
    margin: 5px 8px;
    padding: 10px;
    border: 1px solid #888;
  }
}
</style>
